package servlet;

//import model.Page;
import model.User;
import service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "admin_user_list",urlPatterns = "/admin/user_list")
public class AdminUserListServlet extends HttpServlet {
    private UserService uService = new UserService();
    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<User> list=uService.GetAllUser();
        System.out.println("User count:"+(list==null?0:list.size()));
        request.setAttribute("userList",list);
        this.getServletContext().removeAttribute("userList");
        this.getServletContext().setAttribute("userList",list); //把整个Web范围内所有名为categoryList的值都改为list
        request.getRequestDispatcher("/admin/user_list.jsp").forward(request, response);//转发到goods_publish.jsp

    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
